function h(){
    var xmlhttp;
    xmlhttp = new XMLHttpRequest();

    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            var json = JSON.parse(xmlhttp.responseText);

            console.log(json.data);


            //排序
            json = json.data.reverse();

            for (var i = 0; i < json.length; i++) {

                var row = document.createElement('div');
                row.className = 'row';
                var col1 = document.createElement("span");
                col1.innerHTML = json[i].studentName;

                var col2 = document.createElement("span");
                col2.innerHTML = json[i].sex;

                var col3 = document.createElement("span");
                col3.innerHTML = json[i].age;

                row.appendChild(col1);
                row.appendChild(col2);
                row.appendChild(col3);

                document.querySelector("#list").appendChild(row);

            }
        }
    };

    xmlhttp.open("GET","http://localhost/ajaxApi/public/index.php/index/student/student",true);
    xmlhttp.send();
}

h();




    document.querySelector("#btn").addEventListener("click",function(){

        var n = document.querySelector("#n").value;

        var s = document.querySelector("#s").value;

        var a = document.querySelector("#a").value;


        //ajax代码
        var xmlhttp;
        xmlhttp=new XMLHttpRequest();
        xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
            document.querySelector("#list").innerHTML = "";

            h();
        }
    };
    xmlhttp.open("GET","http://localhost/ajaxApi/public/index.php/index/student/addstudent?studentName="+n+"&sex="+s+"&age="+a,true);
    xmlhttp.send();
});

